void do_div( int num, int radix )
{
	unsigned long temp;
	unsigned char where[10];
	unsigned char t = 10;

	where[0] = '/0';
	do
	{
	temp = (unsigned long) num % radix;
	if ( temp < 10 )
		where[10] = (char)(temp + '0');
		//putc( temp + '0' );
	else 
		where[t--] = (char)(temp + 'A');
		//putc( temp + 'A' );
	num = (unsigned long) num / radix;
	} 
	while ( num != 0 );
		
	monitor_write( where );
}	

void itoa(char *buf, int base, int d, signed int length, char flags)
{
   char *p = buf;
   char *p1, *p2;
   unsigned long ud = d;
   int divisor = 10;

   /* If %d is specified and D is minus, put `-' in the head. */
   if(base == 10 && d < 0)
   {
      *p++ = '-';
      buf++;
      ud = -d;
   }
   else if( base == 16 )
      divisor = 16;
   else if( base < 16 )
	   divisor = base;

   /* Divide UD by DIVISOR until UD == 0. */
	do
	{
		int remainder = ud % divisor;
		// funky if
		*p++ = (remainder < 10) ? remainder + '0' : remainder + flags - 10;
		length--;
	}
	while(ud /= divisor);

   
	while(length > 0)
	{
		*p++ = '0';
		length--;
	}

	/* Terminate BUF. */
	*p = 0;

	/* Reverse BUF. */
	p1 = buf;
	p2 = p - 1;
	while(p1 < p2)
	{
		char tmp = *p1;

		*p1 = *p2;
		*p2 = tmp;
		p1++;
		p2--;
	}
}

void sitoa( char *buf, int base, int d )
{
	char *p = buf;
	char *p1, *p2;
	unsigned long ud = d;
	int divisor = 10;
	
	/* If %d is specified and D is minus, put `-' in the head. */
	if(base == 10 && d < 0)
	{
		*p++ = '-';
		buf++;
		ud = -d;
		
	}
	else if(base == 16)
		divisor = 16;
	else if ( base == 2 )
	{
		divisor = base;
		
	}

	/* Divide UD by DIVISOR until UD == 0. */
	do
	{
		int remainder = ud % divisor;

		*p++ = (remainder < 10) ? remainder + '0' : remainder + 'a' - 10;
		//length--;
	}
	while(ud /= divisor);
	
	/*
	while( (length % 4) != 0)
	{
		*p++ = '0';
		length--;
	}
	*/

	/* Terminate BUF. */
		*p = 0;

	/* Reverse BUF. */
		p1 = buf;
		p2 = p - 1;
	while(p1 < p2)
	{
		char tmp = *p1;

		*p1 = *p2;
		*p2 = tmp;
		p1++;
		p2--;
	}
}



